//
//  BtnCollectionView.swift
//  GFWB
//
//  Created by iSolar on 2017/4/17.
//  Copyright © 2017年 iSolar. All rights reserved.
//

import UIKit

private let btnCell = "btnCollectionViewCell"
private let edgeMargin : CGFloat = 15

class BtnCollectionView: UICollectionView {
    var images = ["找人","上海","游戏","直播","电影","夺宝","尤物","NBA","股票","更多"]
    var titleArr = ["找人","上海","游戏","直播","电影","夺宝","尤物","NBA","股票","更多"]
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        // 设置collectionView的属性
        register(UINib(nibName:"BtnCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: btnCell)
        dataSource = self
    }
}

// MARK:- collectionView的数据源方法
extension BtnCollectionView : UICollectionViewDataSource, UICollectionViewDelegate {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return images.count
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        // 1.创建cell
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: btnCell, for: indexPath) as! BtnCollectionViewCell
        // 2.给cell设置数据
        cell.backgroundColor = UIColor.white
        var str: NSString = NSString();
        str = images[indexPath.item] as NSString
        cell.image = UIImage(named:str as String)
        cell.label.text = indexPath.item <= titleArr.count - 1 ? titleArr[indexPath.item] : nil
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        
    }
}

